//
//  SQListViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/7.
//

#import "SQListViewController.h"

#import "SQListModel.h"
#import "SQReportDeleteModel.h"

#import "SQQueryViewController.h"
#import "SQDetailsModifyViewController.h"

@interface SQListViewController ()<BaseTableVCInterface>

@end

@implementation SQListViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    self.navigationItem.title = @"隐患列表";
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getListData) name:@"list" object:nil];
    [self getListData];
    LC_WEAK_SELF
    self.cellTitleIndex = ^(NSString * str, int key) {
        SQListModelData * dataModel = weakSelf.dataSouece[key];
        if ([str isEqualToString:@"confirm"]) {
            SQDetailsModifyViewController * detailsModifyVC = SQDetailsModifyViewController.new;
            detailsModifyVC.hd_id = dataModel.hd_id;
            [weakSelf pushVC:detailsModifyVC];
            
        }else if ([str isEqualToString:@"look"]){
            SQQueryViewController * queryVC = SQQueryViewController.new;
            queryVC.hd_id = dataModel.hd_id;
            [weakSelf pushVC:queryVC];
            
        }else if ([str isEqualToString:@"del"]){
            
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"是否删除" message:@"" preferredStyle:UIAlertControllerStyleAlert];

                   

                   [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                   }]];

                   

                  [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                      
                      [SQReportDeleteModel getDataWithParams:@{@"hd_id":dataModel.hd_id} WithCallBack:^(SQReportDeleteModel * data) {
                          [CCToast showMessage:@"删除成功"];
                          [weakSelf getListData];
                      }];
                      

                   }]];


                 
                  [weakSelf presentViewController:alertController animated:YES completion:nil];
          
            
        }
    };
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self getListData];
    }];
    
}

-(void)getListData{
    [SQListModel getDataWithParams:@{@"hd_report_person_id":UID,@"hd_enterprise":MEnterpriseId}  WithCallBack:^(SQListModel * data) {
        [self detailModelwithArr:data.data withCallBack:nil];
        [self reloadTableView];
    }];
}



-(BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    return self.dataSouece[indexPath.row];
}



-(NSInteger)rowsCount:(NSInteger)section{
    return self.dataSouece.count;
}


- (NSArray<NSArray<NSString *> *> *)classArr{
    return @[@[@"SQConfirmTableViewCell"]];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
